def ptriangle(n):
    lst = []
    for i in range(1,n+1):
        lst.append(str(i))
    llst=len(lst)
    if n > 9:
        x = n-9
        b = 9
    else:
        x = 0
        b = llst
    bit = x * 3 + b * 2 - 1
    midlist = []
    print("上三角")
    for j in lst:
        midlist.insert(0,j)
        st = ' '.join(midlist)
        print("{:>{}}".format(st,bit))
    print("下三角")
    def mycounter():
        count = 0
        while True:
            yield count
            count += 1
    cc = mycounter()
    while True:
        c = next(cc)
        if c > n:
            break
        stt = ' '.join(midlist[c:])
        print("{:>{}}".format(stt, bit))

sorted(range(5),key=lambda x:10-x)





ptriangle(12)



